/**
 * 报名管理
 */
import {searchIndustry, searchClasses, searchEnrollListByPage, batchUpdateStatus} from "@/api/regManagementApi";

export default {
    data() {
        return {
            visible: false,
            industryOptions: [{//行业
                name: '全部',
                id: null
            }],
            classOptions: [{//班级
                className: '全部',
                id: null
            }],
            searchForm: {
                classes: null,
                proId: null,
            },
            tableData: [],
            multipleSelection: [],
            auditParam: {//审核数据
                status: 0,
                ids: []
            },
            //分页
            total: 0,
            page: 1,
            size: 10
        }
    },
    created() {
        this.getIndustryList();
        this.getClassList();
        this.getEnrollList();

    },
    methods: {
        //查询行业
        getIndustryList() {
            searchIndustry().then(res => {
                this.industryOptions = [...this.industryOptions, ...res];
            }, err => {
            })
        },
        //查询班级
        getClassList() {
            searchClasses().then(res => {
                this.classOptions = [...this.classOptions, ...res];
            }, err => {
            })
        },
        //查询报名数据
        getEnrollList() {
            this.searchForm.size = this.size;
            this.searchForm.page = this.page;
            searchEnrollListByPage(this.searchForm).then(res => {
                this.total = res.total;
                this.tableData = res.list;
            }, err => {
            })
        },
        //切换专业
        proIdChange() {
            this.getEnrollList();
        },
        //切换班级
        classesChange() {
            this.getEnrollList();
        },

        //获取状态对应的label
        getStatusLabel(status) {
            let label = '';
            switch (status) {
                case 0:
                    label = '待审核';
                    break;
                case 1:
                    label = '审核通过';
                    break;
                case 2:
                    label = '不通过';
                    break;
            }
            return label;
        },
        //获取状态对应的样式
        getStatusCss(status) {
            let c = '';
            switch (status) {
                case 0:
                    c = 'c-e09017'
                    break;
                case 1:
                    c = 'c-0f65fa'
                    break;
                case 2:
                    c = 'c-ff0000'
                    break;
            }
            return c;
        },

        handleSelectionChange(val) {
            this.multipleSelection = val;
        },
        //审核弹窗
        showAuditAlert() {
            this.$confirm('是否通过审核?', '审核', {
                distinguishCancelAndClose: true,
                confirmButtonText: '通过',
                cancelButtonText: '不通过',
                type: "warning"
            })
                .then(() => {
                    this.auditParam.status = 1;
                    this.updateStatus();
                })
                .catch(action => {
                    if (action === 'cancel') {
                        this.auditParam.status = 2;
                        this.updateStatus();
                    }
                });
        },
        //单个审核
        auditOne(item) {
            this.auditParam.ids = [];
            this.auditParam.ids.push(item.id);
            this.showAuditAlert();
        },
        //批量操作
        allOption() {
            if (this.multipleSelection.length == 0) {
                this.$message.error('请至少选择一条以上数据进行操作！');
                return false;
            }
            this.auditParam.ids = [];
            this.multipleSelection.forEach(item => {
                this.auditParam.ids.push(item.id);
            });
            this.showAuditAlert();
        },
        //修改报名状态（审核）
        updateStatus() {
            batchUpdateStatus(this.auditParam).then(res => {
                this.$message.success("审核成功");
                this.getEnrollList();
            }, err => {
            })
        },

        //分页
        handleSizeChange(val) {
            this.size = val;
            this.getEnrollList();
        },
        handleCurrentChange(val) {
            this.page = val;
            this.getEnrollList();
        }
    }
}